package org.wk.common.sms;





import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

import java.io.UnsupportedEncodingException;



public class SendMsg_webchinese {

    public static String sendSms(String mobileNumber,String smsCode){
        String result = "";
        try {
            HttpClient client = new HttpClient();
            PostMethod post = new PostMethod("http://gbk.api.smschinese.cn");
            post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");//在头文件中设置转码
            NameValuePair[] data ={ new NameValuePair("Uid", "m17042900183"),new NameValuePair("Key", "d41d8cd98f00b204e980"),new NameValuePair("smsMob",mobileNumber),new NameValuePair("smsText","您的验证码为:"+smsCode+",该验证码2分钟内有效,请勿泄露与他人.")};
            post.setRequestBody(data);

            client.executeMethod(post);
            Header[] headers = post.getResponseHeaders();
            int statusCode = post.getStatusCode();
            System.out.println("statusCode:"+statusCode);
            for(Header h : headers)
            {
                System.out.println(h.toString());
            }
            result = new String(post.getResponseBodyAsString().getBytes("gbk"));
            if(result.equals("1")){
                result="OK";
            }
        }catch (Exception e){
            result = "NO";
        }

        return result;
    }

    public static void main(String[] args) {
        System.out.println(sendSms("15188331362","666666"));
    }


}
